package com.topscore.uke.mvp.model;

import com.topscore.uke.mvp.contractors.GetSmsCodeContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.ApiService;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;
import com.topscore.uke.network.retrofit.NetClient;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/9/13.
 */

public class GetSmsCodeModel implements GetSmsCodeContractor, GetSmsCodeContractor.Model {
    ApiService service = NetClient.getInstance().net().create(ApiService.class);

    private Listener listener;

    public GetSmsCodeModel(Listener listener) {
        this.listener = listener;
    }
    @Override
    public void get(String phone) {
        service.getSmsCode(phone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(listener) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        listener.onGetSuccess();
                    }
                });
    }
}
